package org.wutopia.leo.applicaiton;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.wutopia.leo.domain.account.Account;
import org.wutopia.leo.domain.account.AccountRepository;


/**
 * 用户资源的应用服务接口
 *
 **/
@Service
public class AccountApplicationService {

    @Autowired
    private AccountRepository repository;

    @Autowired
    private PasswordEncoder passwordEncoder;

    public void createAccount(Account account) {
        account.setPassword(passwordEncoder.encode(account.getPassword()));
        repository.save(account);
    }

    public Account findAccountByUsername(String username) {
        return repository.findByUsername(username);
    }

    public void updateAccount(Account account) {
        repository.save(account);
    }

}
